<?php

/**
 *
 */
class ProfileTopMatchsController extends Controller {

  public $content = array();

  public function init() {

   /* if (user()->getUserProperty('username') == '')
      $this->redirect(FRONT_SITE_URL);*/
  }

  public function actionIndex() {
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/peoplemedia_002.js", CClientScript::POS_BEGIN);
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/profileedit.js", CClientScript::POS_BEGIN);
    $this->layout = 'main_search';
    $mProfile = new mProfile();
    $profile = $mProfile->getProfile(user()->getUserProperty('user_id'));
    $data = $this->setDataForUser($profile);
    
     $result['status'] = 'Success';
    //$purifier = new CHtmlPurifier();
    //echo CJSON::encode($result);
    YII::app()->end();
        
		
    $data['photos'] = mUserPhotos::model()->getPhotosPrimary(user()->getUserProperty('user_id'));
    if ($data['photos'] == false) {
      $data['photos'] = mUserPhotos::model()->getPhotosRequestPrimary(user()->getUserProperty('user_id'));
    }
    Yii::app()->session['profileUser'] = $profile;
    $data['percent'] = $this->getPercentUserAnswer();
    //var_dump($profile['gender']);exit();
    if ($profile['gender'] == 'male')
      $pers_ques = mPersonalityQuestions::model()->getDataPerQuesWithUserAns('male', user()->getUserProperty('user_id'));
    else
      $pers_ques = mPersonalityQuestions::model()->getDataPerQuesWithUserAns('female', user()->getUserProperty('user_id'));

    if ($profile['gender'] == 'male') {
      $this->render('/profiletopmatchs/member_profile', array(
          'model' => $profile,
          'data' => $data,
          'pers_ques' => $pers_ques
      ));
    } else {
      $this->render('/profiletopmatchs/member_profile_women', array(
          'model' => $profile,
          'data' => $data,
          'pers_ques' => $pers_ques
      ));
    }
    
  }
  
  
  public function actionSendMessageDetechNull(){
    $result['status'] = 'Success';
    $purifier = new CHtmlPurifier();
    if(isset($_POST['EncodedMemberId']) && isset($_POST['Message'])){
      $mUserMessage = new mUserMessage();
      $mUserMessage->user_id = user()->getUserProperty('user_id');
      $mUserMessage->user_messaged = $purifier->purify($_POST['EncodedMemberId']);
      $mUserMessage->datetime_send = date('Y-m-d H:i:s');
      $mUserMessage->text = $purifier->purify($_POST['todaysmatchmessagebody']);
      $mUserMessage->draft = 0;
      $mUserMessage->read = 1;
      $mUserMessage->feature_name = $purifier->purify('todaymatchs');
      $mUserMessage->from_page = $purifier->purify('todaymatchs');
      $mUserMessage->save();
    }
    echo CJSON::encode($result);
    YII::app()->end();
  }

  public function actionViewProfile() {
    //echo user()->getUserProperty('gender');
      //echo 'abc';
      //exit();
      //var_dump($_POST['abc']);exit();
      
      $models = new mUserVote();
      
      $models = $models->getUserVote(user()->getUserProperty('user_id'),5);
      if(isset($_POST['messagebody'])){
        //echo 'abc';
        //app()->end();
        //exit();
       //dump($_POST['todaysmatchmessagebody']); die;
      $purifier = new CHtmlPurifier();
      $mUserMessage = new mUserMessage();
      $mUserMessage->user_id = user()->getUserProperty('user_id');
      $mUserMessage->user_messaged = $purifier->purify($models[1]['user_id']);
      $mUserMessage->datetime_send = date('Y-m-d H:i:s');
      $mUserMessage->text = $purifier->purify($_POST['messagebody']);
      $mUserMessage->draft = 0;
      $mUserMessage->read = 1;
      $mUserMessage->feature_name = $purifier->purify('todaymatchs');
      $mUserMessage->from_page = $purifier->purify('todaymatchs');
      $mUserMessage->save();
      $result = array();
      echo CJSON::encode($result);
    }
    
      
      
      //dump($models);exit();
      //dump($models[1]['user_id']); die();
      

        //mUserVote->order = 'RAND()';
        //$criteria->where = '';
         //$models = User::model()->with('profile','userPhoto')->find($mUserVote);
        //$this->renderPartial('todaymatchs',compact('models')); 
        

    $this->layout = 'main_topmatchs';
    $this->content['addCss'] = array('profile.css', 'whoimlookingfor.css');
   if (!empty($models[1]['user_id'])) {
       Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/peoplemedia.js", CClientScript::POS_BEGIN);
      Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/jquery_002.js", CClientScript::POS_BEGIN);
      Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/Profile.js", CClientScript::POS_BEGIN);
      
      $mProfileUser = new mProfile();
      $profileUser = $mProfileUser->getProfile(user()->getUserProperty('user_id'));

      $mProfile = new mProfile();
      $profile = $mProfile->getProfile($models[1]['user_id']);
      $dataForImgSlide = array('female' => 1, 'male' => 2, 1 => 'her', 2 => 'him');
      if ($profile != false) {
        $photosPrimary = mUserPhotos::model()->getPhotosPrimary($models[1]['user_id']);
        if ($photosPrimary == false) {
          $photosPrimary = mUserPhotos::model()->getPhotosRequestPrimary($models[1]['user_id']);
        }
        if ($photosPrimary != false) {
          
        }

        $photosAlbum = mUserPhotos::model()->getPhotosAlbum($models[1]['user_id']);
        $photosAllAlbum = mUserPhotos::model()->getAllPhotosWithUserLike($models[1]['user_id'], user()->getUserProperty('user_id'));

        $data = $this->setDataForUser($profile);
        $photosSlideShow = CJSON::encode($photosAllAlbum);
        $photosSlideShow = str_replace('"true"', 'true', $photosSlideShow);
        $getFavorite = mUserFavorite::model()->getUserFavorite(user()->getUserProperty('user_id'),$models[1]['user_id']);
        $this->saveViewProfile(user()->getUserProperty('user_id'), $models[1]['user_id']);
        //dump($models);
        $this->render('/profiletopmatchs/view_profile', array(
            'profile' => $profile,
            'photosPrimary' => $photosPrimary,
            'photosAlbum' => $photosAlbum,
            'data' => $data,
            'dataForImgSlide' => $dataForImgSlide,
            'photosSlideShow' => $photosSlideShow,
            'models' => $models,
            'isFavorite' => $getFavorite
        ));
      }
      else
        $this->render('/profiletopmatchs/view_no_profile');
    }else {
      $this->render('/profiletopmatchs/view_no_profile');
    }
    
    /*$result['status'] = 'Success';
    //$purifier = new CHtmlPurifier();
    if(isset($_POST['todaysmatchmessagebody'])){
        
      echo CJSON::encode($result);
    }
    
    
    YII::app()->end();*/
    
    //?profile=293AEAB56175F863
  }

  public function actionGetProfilePhotos() {
    $result = array();
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  public function actionRecordNextPhoto() {
    $result = array();
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  public function actionSaveToFavorites() {
    $result = array('status' => 'Error',
        'message' => 'Whoops... something\'s amiss');

    if (r()->isPostRequest && isset($_POST['EncodedMemberId'])) {
      $mUserFavorite = new mUserFavorite();
      $checkExists = $mUserFavorite->find('user_id=:user_id and user_favorited=:user_favorited', array(':user_id' => user()->getUserProperty('user_id'), ':user_favorited' => $_POST['EncodedMemberId']));
      if ($checkExists == null) {
        $mUserFavorite->user_id = user()->getUserProperty('user_id');
        $mUserFavorite->user_favorited = $_POST['EncodedMemberId'];
        $mUserFavorite->date_favorite = date('Y-m-d');
        if ($mUserFavorite->save()) {
          $result['status'] = 'Success';
        }
      }
    }
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  public function actionUnfavorite() {
    $result = array('status' => 'Error',
        'message' => 'Whoops... something\'s amiss');
    if (r()->isPostRequest && isset($_POST['EncodedMemberId'])) {
      $mUserFavorite = new mUserFavorite();
      $checkExists = $mUserFavorite->find('user_id=:user_id and user_favorited=:user_favorited', array(':user_id' => user()->getUserProperty('user_id'), ':user_favorited' => $_POST['EncodedMemberId']));
      if ($checkExists != null) {
        if ($mUserFavorite->deleteAll('user_id=:user_id and user_favorited=:user_favorited', array(':user_id' => user()->getUserProperty('user_id'), ':user_favorited' => $_POST['EncodedMemberId'])) == 1) {
          $result['status'] = 'Success';
        }
      }
    }
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  private function getBodyMail($email, $linkprofile) {
    $content = $email . ' thought you would be interested in this profile:';
    $content .= 'To view this profile <a href="' . $linkprofile . '">click here</a>';
    $content .= $email . ' also said:';
    $content .= 'Hey, I came across this profile on BBPeopleMeet.com and thought you might be interested.';
    $content .= 'You have received this email because your friend thought you would like this profile. You can stop email delivery options or unsubscribe at anytime if you click here. You may also click here to contact us offline via our mailing address, BBPeopleMeet.com, PO Box 12627, Dallas, TX 75225. ';
    return $content;
  }

  public function actionShareProfile() {

    $result = array('status' => 'Error',
        'message' => 'Whoops... something\'s amiss');
    if (r()->isPostRequest && isset($_POST['EncodedMemberId'])) {
      $mUser = new User();
      $checkExists = $mUser->find('user_id=:user_id', array(':user_id' => $_POST['EncodedMemberId']));
      if ($checkExists != null && $_POST['EmailAddress'] != '') {
        if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $_POST['EmailAddress'])) {
          /* $body = $this->getBodyMail($_POST['EmailAddress'],'http://localhost/yii/project2/user/profile/viewprofile?profile='.$_POST['EncodedMemberId']);
            EmailHelper::send($_POST['EmailAddress'], 'subject',$body,$_POST['EmailAddress']); */
          $result['status'] = 'Success';
          $result['message'] = 'Your message has been sent.';
        } else {
          $result['status'] = 'Success';
          $result['message'] = 'Invalid Email address.';
        }
      } else {
        $result['status'] = 'Success';
        $result['message'] = 'Invalid Email address.';
      }
    }

    echo CJSON::encode($result);
    Yii::app()->end();
  }

  public function actionReportConcern() {
    $result = array('status' => 'Error',
        'message' => 'Whoops... something\'s amiss');

    if (r()->isPostRequest && isset($_POST['EncodedMemberId'])) {
      $mUser = new User();
      $checkExists = $mUser->find('user_id=:user_id', array(':user_id' => $_POST['EncodedMemberId']));
      if ($checkExists != null) {
        $mUserReport = new mUserReport();
        $mUserReport->user_id = user()->getUserProperty('user_id');
        $mUserReport->user_reported = $_POST['EncodedMemberId'];
        $mUserReport->report_id = $_POST['ConcernId'];
        $mUserReport->datetime = date('Y-m-d H:i:s');
        if ($_POST['BlockUser'] == true)
          $mUserReport->block = 1;
        else
          $mUserReport->block = 0;
        if ($mUserReport->save()) {
          $result['status'] = 'Success';
          $result['message'] = 'Thank you, your concern is taken very seriously and may require a few days to fully investigate. This user has been blocked.';
        }
      }
    }
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  public function actionBlockUser() {
    $result = array('status' => 'Error',
        'message' => 'Whoops... something\'s amiss');
    if (r()->isPostRequest && isset($_POST['EncodedMemberId'])) {
      $mUser = new User();
      $checkExists = $mUser->find('user_id=:user_id', array(':user_id' => $_POST['EncodedMemberId']));
      if ($checkExists != null && $_POST['BlockUser'] == true) {
        $mUserBlock = new mUserBlock();
        $mUserBlock->user_id = user()->getUserProperty('user_id');
        $mUserBlock->user_blocked = $_POST['EncodedMemberId'];
        if ($mUserBlock->save()) {
          $result['status'] = 'Success';
        }
      }
    }
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  public function actionSendBirthdayFlirt() {
    $result = array('status' => 'Error',
        'message' => 'Whoops... something\'s amiss');

    $result['status'] = 'Success';
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  public function actionGetInteraction() {
    $result = array('status' => 'Error',
        'message' => 'Whoops... something\'s amiss');

    $result['status'] = 'Success';
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  public function actionSendMessage() {
    $result = array('status' => 'Error',
        'message' => 'Whoops... something\'s amiss');

    $result['status'] = 'Success';
    $result['redirect'] = FRONT_SITE_URL;
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  public function actionLikePhoto() {
    $result = array('status' => 'Error',
        'message' => 'Whoops... something\'s amiss');
    if (r()->isPostRequest && isset($_POST['EncodedMemberId'])) {
      $mUser = new User();
      $checkExists = $mUser->find('user_id=:user_id', array(':user_id' => $_POST['EncodedMemberId']));
      if ($checkExists != null) {
        $mPhotosLike = new mPhotosLike();
        $mPhotosLike->user_id = $_POST['EncodedMemberId'];
        $mPhotosLike->photos_id = $_POST['ObjectId'];
        $mPhotosLike->like = 1;
        $mPhotosLike->draft_like = 0;
        $mPhotosLike->primary_photos = 0;
        $mPhotosLike->viewed = 0;
        $mPhotosLike->text = '';
        if ($mPhotosLike->save()) {
          $result['status'] = 'Success';
        }
        $errores = $mPhotosLike->getErrors();
        var_dump($errores);
      }
    }
    $result['status'] = 'Success';
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  public function actionCommentPhoto() {
    $result = array('status' => 'Error',
        'message' => 'Whoops... something\'s amiss');

    $result['status'] = 'Success';
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  public function actionAstrologerCompatability() {
    $result = array('status' => 'Error',
        'message' => 'Whoops... something\'s amiss');

    $result['status'] = 'Success';
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  public function actionSendFlirt() {
    $result = array('status' => 'Error',
        'message' => 'Whoops... something\'s amiss');

    $result['status'] = 'Success';
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  /*
   * Description: access page upload media of people
   */

  public function actionMediaUpload() {
    $this->layout = 'main_search';
    $mProfile = new mProfile();
    $profile = $mProfile->getProfile(user()->getUserProperty('user_id'));
    $this->content['addCss'] = array('upload_photo.css', 'facebook_csphotoselector.css');
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/all.js", CClientScript::POS_BEGIN);
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/peoplemedia.js", CClientScript::POS_BEGIN);
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/photoupload.js", CClientScript::POS_BEGIN);
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/csphotoselector.js", CClientScript::POS_BEGIN);
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/facebookimport.js", CClientScript::POS_BEGIN);

    if (isset($_GET['type']) && $_GET['type'] == 1) {
      if (isset($profile) && count($profile) > 0) {
        mUserPhotos::model()->deleteByPk($_GET['mediaid']);
      }
    }

    if (isset($_POST['media_id'])) {
      if (isset($profile) && count($profile) > 0) {
        $user_photos = mUserPhotos::model()->findByPk($_POST['media_id']);
        if ($user_photos != null) {
          if ($_POST['processForm'] == 'update_title') {
            $user_photos->text = $_POST['title'];
            $user_photos->save();
          } else if ($_POST['processForm'] == 'show_in_profile') {
            //$user_photos->text = $_POST['title'];
            //var_dump($user_photos);
            //$user_photos->primarykey;
            //exit();
            $user_photos->updateRequestPrimary($_POST['media_id'], user()->getUserProperty('user_id'));
            //$user_photos->save();
          }
        }
      }
    }

    $photos = mUserPhotos::model()->getPhotos(user()->getUserProperty('user_id'));
    if (count($photos) > 0) {
      $photosPrimary = mUserPhotos::model()->getPhotosPrimary(user()->getUserProperty('user_id'));
      if ($photosPrimary == false) {
        $photosPrimary = mUserPhotos::model()->getPhotosRequestPrimary(user()->getUserProperty('user_id'));
      }
      $photosAlbum = mUserPhotos::model()->getPhotosAlbum(user()->getUserProperty('user_id'));

      $this->render('/profiletopmatchs/member_upload_multifile', array(
          'model' => $profile,
          'photosPrimary' => $photosPrimary,
          'photosAlbum' => $photosAlbum,
          'total_photos' => TOTAL_PHOTOS - count($photos)
      ));
    } else {
      $this->render('/profiletopmatchs/member_upload_primary', array(
          'model' => $profile
      ));
    }
  }

  /*
   * Description: grab photos fb
   */

  public function actionGrabfacebookphoto() {
    $result['redirect'] = '';
    $photos = mUserPhotos::model()->getPhotos(user()->getUserProperty('user_id'));
    if (count($photos) < 30) {
      if (isset($_POST['photourl'])) {
        $photourl = $_POST['photourl'];
        $photourl = explode('&_', $photourl);
        $photourl = $photourl[0];
        $extension = explode('.', $photourl);
        $extension = $extension[count($extension) - 1];

        $mUserPhotos = new mUserPhotos();
        $mUserPhotos->insertUserPhotos(user()->getUserProperty('user_id'));
        $namePhotos = Yii::app()->db->getLastInsertID() . '_' . user()->getUserProperty('user_id') . '.' . $extension;
        $filePhotos = UPLOAD_PATH . 'photos/images/' . $namePhotos;
        $this->curl_img_fb($photourl, $filePhotos);
        $idUserPhotos = Yii::app()->db->getLastInsertID();
        $mUserPhotos->updateUserPhotos($idUserPhotos, $namePhotos);
        ImageHelper::thumbWithDir(132, 165, $filePhotos, UPLOAD_PATH . 'photos/thumbs/');
        $result['redirect'] = 'mediaid=' . $idUserPhotos;
      } else {
        
      }
    } else {
      $errores['file_upload'] = 'Only uploaded 30 photos';
    }
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  public function saveViewProfile($user_id, $user_id_viewed) {
    if (mUserView::model()->find('user_id=:user_id and user_id_viewed=:user_id_ivew', array(':user_id' => $user_id, ':user_id_ivew' => $user_id_viewed)) == null) {
      $mUserView = new mUserView();
      $mUserView->user_id = $user_id;
      $mUserView->user_id_viewed = $user_id_viewed;
      $mUserView->date_view = date('Y-m-d H:i:s');
      $mUserView->save();
    } else {
      //$mUserView = new mUserView();
      $mUserView = mUserView::model()->find('user_id=:user_id and user_id_viewed=:user_id_ivew', array(':user_id' => $user_id, ':user_id_ivew' => $user_id_viewed));
      $mUserView->date_view = date('Y-m-d H:i:s');
      $mUserView->save();
    }
  }

  private function curl_img_fb($link_img, $link_save_img) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 130);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    //curl_setopt($ch, CURLOPT_COOKIEJAR, $COOKIEFILE);
    curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
    curl_setopt($ch, CURLOPT_TIMEOUT, 120);
    curl_setopt($ch, CURLOPT_URL, $link_img);
    $data1 = curl_exec($ch);
    $file = $link_save_img;
    file_put_contents($file, $data1);
  }

  /*
   * Description: Process upload file of people JPG,PNG,TIF,BMP,GIF <5MB
   */

  public function actionProcessUpload() {
    $errores = '';
    $this->layout = 'main_search';
    $mProfile = new mProfile();
    $profile = $mProfile->getProfile(user()->getUserProperty('user_id'));
    $this->content['addCss'] = array('upload_photo.css', 'facebook_csphotoselector.css');
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/peoplemedia.js", CClientScript::POS_BEGIN);
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/photoupload.js", CClientScript::POS_BEGIN);
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/csphotoselector.js", CClientScript::POS_BEGIN);
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/facebookimport.js", CClientScript::POS_BEGIN);
    $photos = mUserPhotos::model()->getPhotos(user()->getUserProperty('user_id'));
    $mUserPhotos = new mUserPhotos('upload1');
    //process upload
    if (count($photos) > 0) {
      if (count($photos) < 30) {
        foreach ($_FILES as $key => $file) {
          $mUserPhotos = new mUserPhotos('upload1');
          $fileUpload = CUploadedFile::getInstanceByName($key);
          $mUserPhotos->file_upload = $fileUpload;
          if ($mUserPhotos->validate()) {
            $mUserPhotos->user_id = user()->getUserProperty('user_id');
            $mUserPhotos->save();
            $namePhotos = $mUserPhotos->photos_id . '_' . $mUserPhotos->user_id . '.' . $mUserPhotos->file_upload->extensionName;
            $mUserPhotos->savePhotos($mUserPhotos->file_upload, $namePhotos);
            $mUserPhotos->link_img = $namePhotos;
            $mUserPhotos->save();
            $filePhotos = UPLOAD_PATH . 'photos/images/' . $namePhotos;
            ImageHelper::thumbWithDir(132, 165, $filePhotos, UPLOAD_PATH . 'photos/thumbs/');
          } else {
            $errores = $mUserPhotos->getErrors();
            echo $errores;
          }
        }
      } else {
        $errores['file_upload'] = 'Only uploaded 30 photos';
      }
    } else {//upload primary image
      $fileUpload = CUploadedFile::getInstanceByName('uploadFile');
      $mUserPhotos->file_upload = $fileUpload;
      if ($mUserPhotos->validate()) {
        $mUserPhotos->user_id = user()->getUserProperty('user_id');
        $mUserPhotos->request = 1;
        $mUserPhotos->save();
        $namePhotos = $mUserPhotos->photos_id . '_' . $mUserPhotos->user_id . '.' . $mUserPhotos->file_upload->extensionName;
        $mUserPhotos->savePhotos($mUserPhotos->file_upload, $namePhotos);
        $mUserPhotos->link_img = $namePhotos;
        $mUserPhotos->save();
        $filePhotos = UPLOAD_PATH . 'photos/images/' . $namePhotos;
        ImageHelper::thumbWithDir(132, 165, $filePhotos, UPLOAD_PATH . 'photos/thumbs/');
      } else {
        $errores = $mUserPhotos->getErrors();
      }
    }

    //render view
    $photos = mUserPhotos::model()->getPhotos(user()->getUserProperty('user_id'));
    if (count($photos) > 0) {
      $photosPrimary = mUserPhotos::model()->getPhotosPrimary(user()->getUserProperty('user_id'));
      if ($photosPrimary == false) {
        $photosPrimary = mUserPhotos::model()->getPhotosRequestPrimary(user()->getUserProperty('user_id'));
      }
      $photosAlbum = mUserPhotos::model()->getPhotosAlbum(user()->getUserProperty('user_id'));

      $this->render('/profiletopmatchs/member_upload_multifile', array(
          'model' => $profile,
          'photosPrimary' => $photosPrimary,
          'photosAlbum' => $photosAlbum,
          'total_photos' => TOTAL_PHOTOS - count($photos)
      ));
    } else {
      $this->render('/profiletopmatchs/member_upload_primary', array(
          'model' => $profile
      ));
    }
  }

  /*
   * Description: Detech js has live
   */

  public function actionTestJsProcessUpload() {
    $result['success'] = 1;
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  /*
   * Description: edit interests
   */

  public function actionEditInterest() {
    $this->layout = 'main_search';
    $mProfile = new mProfile();
    $profile = $mProfile->getProfile(user()->getUserProperty('user_id'));
    $data_interest_img = array();
    $data_interest_img[] = $profile['interestImg1'];
    $data_interest_img[] = $profile['interestImg2'];
    $data_interest_img[] = $profile['interestImg3'];


    $this->render('/profiletopmatchs/member_interests', array(
        'model' => $profile,
        'data_interest_img' => $data_interest_img
    ));
  }

  /*
   * Description: change profile grew up
   */

  public function actionMemberHometown() {
    $this->layout = 'main_search';
    Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/account_settings.css");
    $mProfile = new mProfile();
    $profile = $mProfile->getProfile(user()->getUserProperty('user_id'));
    $data_country = array();
    $mCountry = mCountries::model()->findAll(array(
        'select' => '*',
        'condition' => 'code NOT IN("US","CA")'
    ));
    foreach ($mCountry as $item) {
      $data_country[] = $item->attributes;
    }

    if (r()->isPostRequest) {
      $mProfile->updateProfile('where_i_grew_up', $_POST['SelectedCountryCode'], Yii::app()->session['profileUser']['profile_id']);
      $this->redirect(FRONT_SITE_URL . 'user/profiletopmatchs');
    }
    else
      $this->render('/profiletopmatchs/member_location_grew_up', array('model' => $profile, 'data_country' => $data_country));
  }

  /*
   * Description: delete profile grewup
   */

  public function actionDropGrewup() {
    $this->layout = 'main_search';
    $mProfile = new mProfile();
    $profile = $mProfile->getProfile(user()->getUserProperty('user_id'));
    $mProfile->updateProfile('where_i_grew_up', '', Yii::app()->session['profileUser']['profile_id']);
    $this->redirect(FRONT_SITE_URL . 'user/profile');
  }

  /*
   * Description: change profile country
   */

  public function actionMemberLocation() {
    //var_dump($_POST);
    $this->layout = 'main_search';
    Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/account_settings.css");
    $mProfile = new mProfile();
    $profile = $mProfile->getProfile(user()->getUserProperty('user_id'));
    if (r()->isPostRequest) {
      if (Yii::app()->request->csrfToken == $_POST['ioBlackBox']) {
        if (isset($_POST['LocationStep'])) {
          if ($_POST['LocationStep'] == 'StateZip') {//SaveLocation
            if (isset($_POST['SelectedCountryCode'])) {
              $session = Yii::app()->session;
              $temp = $session['tmp_profile_user_country'];
              $temp['country'] = $_POST['SelectedCountryCode'];
              $session['tmp_profile_user_country'] = $temp;

              if ($_POST['SelectedCountryCode'] == 'CA' || $_POST['SelectedCountryCode'] == 'US') {
                $this->render('/profiletopmatchs/member_location_zipcode');
              } else {
                $this->render('/profiletopmatchs/member_location_statecity');
              }
            } else {
              $this->render('/profiletopmatchs/member_location');
            }
          } else if ($_POST['LocationStep'] == 'SaveLocation') {
            $mProfile = new mProfile();
            $session = Yii::app()->session;
            $mProfile->updateProfile('country', $session['tmp_profile_user_country']['country'], Yii::app()->session['profileUser']['profile_id']);
            if ($session['tmp_country']['country'] == 'CA' || $session['tmp_country']['country'] == 'US')
              $mProfile->updateProfile('postcode', $_POST['ZipCode'], Yii::app()->session['profileUser']['profile_id']);
            else {
              $mProfile->updateProfile('state', $_POST['StateProvince'], Yii::app()->session['profileUser']['profile_id']);
              $mProfile->updateProfile('city', $_POST['City'], Yii::app()->session['profileUser']['profile_id']);
            }
            unset(Yii::app()->session['tmp_country']);
            $this->redirect(FRONT_SITE_URL . 'user/profile');
            Yii::app()->end();
          } else {
            $this->redirect(FRONT_SITE_URL . 'user/profile');
            Yii::app()->end();
          }
        } else {
          $this->redirect(FRONT_SITE_URL . 'user/profile');
          Yii::app()->end();
        }
      } else {
        $this->redirect(FRONT_SITE_URL . 'user/profile');
        Yii::app()->end();
      }
    } else {
      unset(Yii::app()->session['tmp_country']);
      Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/account_settings.css");
      $this->render('/profiletopmatchs/member_location');
    }
  }

  /*
   * Desription: set data for user
   * return $data
   */

  private function setDataForUser($profile) {
    $data['date_birth'] = $this->calculateProfileBirthDate($profile['birthdate']);
    $data['seeking'] = $this->returnSeeing($profile['seeking']);
    $data['tall'] = $this->returnHeight(number_format($profile['tall'] / 30.48, 1));
    $data['looking'] = $this->returnLooking($profile['looking']);
    $data['occupation'] = $this->returnOccupation($profile['occupation']);
    $data['education'] = $this->returnEducation($profile['education']);
    $data['income'] = $this->returnIncome($profile['income']);
    $data['religion'] = $this->returnReligion($profile['religion']);
    $data['political'] = $this->returnPolitical($profile['political_affiliation']);
    $data['bodytype'] = $this->returnBodyType($profile['body_type']);
    $data['hair'] = $this->returnHairColor($profile['hair_color']);
    $data['eyes_color'] = $this->returnEyeColor($profile['eyes_color']);
    $data['ethnicity'] = $this->returnEthnicity($profile['ethnicity']);
    $data['marial_status'] = $this->returnMarialStatus($profile['marial_status']);
    $data['childandliving'] = $this->returnChildAndLiving($profile['children'], $profile['children_living']);
    $data['pet'] = $this->returnPet($profile['pet']);
    $data['smoking'] = $this->returnSmoking($profile['smoke']);
    $data['cooking'] = $this->returnCooking($profile['question1']);
    $data['consider'] = $this->returnConsider($profile['question2']);
    $data['romantic'] = $this->returnRomantic($profile['question3']);
    $data['punctual'] = $this->returnPunctual($profile['question4']);
    $data['go_movie'] = $this->returnGoMovie($profile['question5']);
    $data['live_theatre'] = $this->returnLiveTheatre($profile['question6']);
    $data['like_reading'] = $this->returnLikeReading($profile['question7']);
    $data['grewup'] = $this->returnGrewUp($profile['where_i_grew_up']);
    $data['zodiac'] = $this->returnZodiac($profile['zodiac']);
    return $data;
  }

  private function returnGrewUp($grewup) {
    $data1[0] = 'no answer';
    $data1[1] = 0;
    $data = mCountries::model()->find('code=:code', array(':code' => $grewup));
    if ($data == null)
      return $data1;
    $data = $data->attributes;

    if ($grewup == null || $grewup == '')
      return $data1;
    if (!isset($data) && !is_array($data))
      return $data1;
    $data1[0] = isset($data['name'])?$data['name']:'';
    $data1[1] = isset($data['code'])?$data['code']:'';

    return $data1;
  }

  private function returnLikeReading($likeReading) {
    $data = Constant::getLikeReadingArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($likeReading == null || $likeReading == '')
      return $data1;

    $data1[0] = isset($data[$likeReading])?$data[$likeReading]:'';
    $data1[1] = $likeReading;

    return $data1;
  }

  private function returnLiveTheatre($liveTheatre) {
    $data = Constant::getLiveTheatreArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($liveTheatre == null || $liveTheatre == '')
      return $data1;

    $data1[0] = isset($data[$liveTheatre])?$data[$liveTheatre]:'';
    $data1[1] = $liveTheatre;

    return $data1;
  }

  private function returnGoMovie($goMovie) {
    $data = Constant::getGoMovieArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($goMovie == null || $goMovie == '')
      return $data1;

    $data1[0] = isset($data[$goMovie])?$data[$goMovie]:'';
    $data1[1] = $goMovie;

    return $data1;
  }

  private function returnPunctual($punctual) {
    $data = Constant::getPunctualArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($punctual == null || $punctual == '')
      return $data1;

    $data1[0] = isset($data[$punctual])?$data[$punctual]:'';
    $data1[1] = $punctual;

    return $data1;
  }

  private function returnRomantic($romantic) {
    $data = Constant::getRomanticArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($romantic == null || $romantic == '')
      return $data1;

    $data1[0] = isset($data[$romantic])?$data[$romantic]:'';
    $data1[1] = $romantic;

    return $data1;
  }

  private function returnConsider($consider) {
    $data = Constant::getConsiderArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($consider == null || $consider == '')
      return $data1;

    $data1[0] = isset($data[$consider])?$data[$consider]:'';
    $data1[1] = $consider;

    return $data1;
  }

  private function returnCooking($cooking) {
    $data = Constant::getCookingrray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($cooking == null || $cooking == '')
      return $data1;

    $data1[0] = isset($data[$cooking])?$data[$cooking]:'';
    $data1[1] = $cooking;

    return $data1;
  }

  private function returnZodiac($zodiac) {
    $data = Constant::getZodiacArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($zodiac == null || $zodiac == '')
      return $data1;

    $data1[0] = isset($data[$zodiac])?$data[$zodiac]:'';
    $data1[1] = $zodiac;

    return $data1;
  }

  private function returnSmoking($smoking) {
    $data = Constant::getSmokerArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($smoking == null || $smoking == 0 || $smoking == -1)
      return $data1;

    $data1[0] = isset($data[$smoking])?$data[$smoking]:'';
    $data1[1] = $smoking;

    return $data1;
  }

  private function returnPet($pet) {
    $data = Constant::getPetArray();
    $data1[0] = 'no answer';
    $data1[1] = $pet;
    //if($pet == 65536) echo 'abc';exit();
    if ($pet == null || $pet == '')
      return $data1;

    $formattedResponse = '';
    $count = 0;
    $ResponseValues = isset($pet) ? explode(',', $pet) : '';
    foreach ($ResponseValues as $item) {
      if ($count == 0)
        $formattedResponse .= isset($data[$item])?$data[$item]:'';
      else
        $formattedResponse .= ', ' . isset($data[$item])?$data[$item]:'';
      $count++;
    }
    if ($formattedResponse != '') {
      $data1[0] = $formattedResponse;
    }
    return $data1;
  }

  private function returnChildAndLiving($child, $living) {
    $data = Constant::getChildArray();
    $data1[0] = '';
    if ($child < 1) {
      $data1 = 'Has no children';
    } else {
      if (isset($living)) {
        if ($living < 1)
          $data1[0] = 'Has ' . $data[$child] . ' children';
        else
          $data1[0] = 'Has ' . $data[$child] . ' child, lives with ' . $data[$living];
      }else {
        $data1[0] = 'Has ' . $data[$child] . ' children';
      }
    }
    $data1[1] = $child;
    $data1[2] = $living;
    return $data1;
  }

  private function returnMarialStatus($marial_status) {
    $data = Constant::getMaritalArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($marial_status == null || $marial_status == 0 || $marial_status == -1)
      return $data1;

    $data1[0] = isset($data[$marial_status])?$data[$marial_status]:'';
    $data1[1] = $marial_status;

    return $data1;
  }

  private function returnEthnicity($ethnicity) {
    $data = Constant::getEthnicityArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($ethnicity == null || $ethnicity == 0 || $ethnicity == -1)
      return $data1;

    $data1[0] = isset($data[$ethnicity])?$data[$ethnicity]:'';
    $data1[1] = $ethnicity;

    return $data1;
  }

  private function returnEyeColor($eyes_color) {
    $data = Constant::getColorArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($eyes_color == null || $eyes_color == 0 || $eyes_color == -1)
      return $data1;

    $data1[0] = isset($data[$eyes_color])?$data[$eyes_color]:'';
    $data1[1] = $eyes_color;

    return $data1;
  }

  private function returnHairColor($hair_color) {
    $data = Constant::getHairColorArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($hair_color == null || $hair_color == 0 || $hair_color == -1)
      return $data1;

    $data1[0] = isset($data[$hair_color])?$data[$hair_color]:'';
    $data1[1] = $hair_color;

    return $data1;
  }

  private function returnBodyType($body_type) {
    $data = Constant::getBodyArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($body_type == null || $body_type == 0 || $body_type == -1)
      return $data1;

    $data1[0] = isset($data[$body_type])?$data[$body_type]:'';
    $data1[1] = $body_type;

    return $data1;
  }

  private function returnPolitical($political) {
    $data = Constant::getPoliticalArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($political == null || $political == 0 || $political == -1)
      return $data1;

    $data1[0] = isset($data[$political])?$data[$political]:'';
    $data1[1] = $political;

    return $data1;
  }

  private function returnReligion($religion) {
    $data = Constant::getReligionArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($religion == null || $religion == 0 || $religion == -1)
      return $data1;

    $data1[0] = isset($data[$religion])?$data[$religion]:'';
    $data1[1] = $religion;

    return $data1;
  }

  private function returnIncome($income) {
    $data = Constant::getIncomeArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($income == null || $income == 0 || $income == -1)
      return $data1;

    $data1[0] = isset($data[$income])?$data[$income]:'';
    $data1[1] = $income;

    return $data1;
  }

  private function returnEducation($education) {
    $data = Constant::getEducationArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    if ($education == null || $education == 0 || $education == -1)
      return $data1;

    $data1[0] = isset($data[$education])?$data[$education]:0;
    $data1[1] = $education;

    return $data1;
  }

  private function returnOccupation($occupation) {
    $data = Constant::getOccupationArray();
    $data1[0] = 'no answer';
    $data1[1] = 0;
    $data1[2] = -1;
    if ($occupation == null || $occupation == 0 || $occupation == -1)
      return $data1;
    $occupation = explode(',', $occupation);
    $data1[0] = $data[$occupation[0]];
    $data1[1] = isset($occupation[1]) ? $occupation[1] : 0;
    $data1[2] = $occupation[0];

    return $data1;
  }

  private function returnLooking($looking) {
    $data = array(-1 => 'Marriage, Serious Relationship, Travel Partner, Casual Relationship, Friendship, Pen pal', 2 => 'Marriage', 4 => 'Serious Relationship', 8 => 'Travel Partner', 16 => 'Casual Relationship', 32 => 'Friendship', 64 => 'Pen pal');
    $data1 = 'no answer';

    $formattedResponse = '';
    $count = 0;
    $ResponseValues = isset($looking) ? explode(',', $looking) : '';
    if ($ResponseValues != '') {
      foreach ($ResponseValues as $item) {
        if ($count == 0)
          $formattedResponse .= isset($data[$item])?$data[$item]:'';
        else
          $formattedResponse .= ', ' . isset($data[$item])?$data[$item]:'';
        $count++;
      }
      if ($formattedResponse != '') {
        $data1 = $formattedResponse;
      }
    }
    return $data1;
  }

  private function returnHeight($height) {
    $data = Constant::getTallArray();
    $data1[0] = $height;
    $data1[1] = isset($data["$height"]) ? $data[$height] : $data["4.5"];
    return $data1;
  }

  private function returnSeeing($seeking) {
    $data = Constant::getSeeking1Array();
    return isset($data[$seeking]) ? $data[$seeking] : $data[1];
  }

  private function calculateProfileBirthDate($birthdate) {
    $data = array();
    $data[0] = $this->calculateYearOld($birthdate);
    $date1 = new DateTime($birthdate);

    $data[1][0] = intval($date1->format('d'));
    $data[1][1] = intval($date1->format('m'));
    $data[1][2] = $date1->format('Y');

    return $data;
  }

  /**
   * Performs the AJAX validation.
   * @param CModel the model to be validated
   */
  protected function performAjaxValidation($model) {
    if (isset($_POST['ajax']) && $_POST['ajax'] === 'user-form') {
      echo CActiveForm::validate($model);
      Yii::app()->end();
    }
  }

  /**
   *  Description: Process update profile of user 
   * 
   */
  public function actionSaveInterest() {
    $hiddenPosition1ImageID = isset($_POST['hiddenPosition1ImageID']) ? $_POST['hiddenPosition1ImageID'] : 0;
    $hiddenPosition2ImageID = isset($_POST['hiddenPosition2ImageID']) ? $_POST['hiddenPosition2ImageID'] : 0;
    $hiddenPosition3ImageID = isset($_POST['hiddenPosition3ImageID']) ? $_POST['hiddenPosition3ImageID'] : 0;
    $interesttext1 = isset($_POST['interesttext1']) ? $_POST['interesttext1'] : '';
    $interesttext2 = isset($_POST['interesttext2']) ? $_POST['interesttext2'] : '';
    $interesttext3 = isset($_POST['interesttext3']) ? $_POST['interesttext3'] : '';

    $mProfile = new mProfile();
    $mProfile->updateProfile('interestImg1', $hiddenPosition1ImageID, Yii::app()->session['profileUser']['profile_id']);
    $mProfile->updateProfile('interestImg2', $hiddenPosition2ImageID, Yii::app()->session['profileUser']['profile_id']);
    $mProfile->updateProfile('interestImg3', $hiddenPosition3ImageID, Yii::app()->session['profileUser']['profile_id']);
    $mProfile->updateProfile('interestText1', $interesttext1, Yii::app()->session['profileUser']['profile_id']);
    $mProfile->updateProfile('interestText2', $interesttext2, Yii::app()->session['profileUser']['profile_id']);
    $mProfile->updateProfile('interestText3', $interesttext3, Yii::app()->session['profileUser']['profile_id']);
    $data['redirect'] = FRONT_SITE_URL . 'user/profile';
    echo CJSON::encode($data);
  }

  /*
   * Get Percent User Answer
   */
  public function getPercentUserAnswer() {
    $mProfile = new mProfile();
    $mProfile = $mProfile->getProfileByUserId(user()->getUserProperty('user_id'));
    $about = 0;
    $greetings = 0;
    $personality = 0;
    $interests = 0;
    $global = 0;
    if($mProfile!=false){
      if($mProfile['looking']!=null) $about += 6.25;
      if($mProfile['occupation']!=null) $about += 6.25;
      if($mProfile['education']!=null) $about += 6.25;
      if($mProfile['income']!=null) $about += 6.25;
      if($mProfile['religion']!=null) $about += 6.25;
      if($mProfile['political_affiliation']!=null) $about += 6.25;
      if($mProfile['where_i_grew_up']!='') $about += 6.25;
      if($mProfile['tall']!=null) $about += 6.25;
      if($mProfile['body_type']!=null) $about += 6.25;
      if($mProfile['hair_color']!=null) $about += 6.25;
      if($mProfile['eyes_color']!=null) $about += 6.25;
      if($mProfile['ethnicity']!=null) $about += 6.25;
      if($mProfile['marial_status']!=null) $about += 6.25;
      if($mProfile['children']!=null) $about += 6.25;
      if($mProfile['pet']!='') $about += 6.25;
      if($mProfile['smoke']!=null) $about += 6.25;
      if($mProfile['greeting1']!=null) $greetings += 33.33;
      if($mProfile['greeting2']!=null) $greetings += 33.33;
      if($mProfile['greeting3']!=null) $greetings += 33.33;
      if($greetings>99) $greetings = 100;
      
      $mAllQuestion = mPersonalityQuestions::model()->findAll('sex=:sex and active=1', array(':sex'=>$mProfile['gender']));
      $mQuesUserAns = mPersonalityQuestions::model()->getQuesUserAns($mProfile['gender'],$mProfile['user_id']);      
      if(count($mAllQuestion) == count($mQuesUserAns)){
        $personality = 100;
      }else{
        $percentOneQuestion = 100/count($mAllQuestion);
        $personality = round($percentOneQuestion * count($mQuesUserAns));
      }
      
      if($mProfile['interestImg1']!=null && $mProfile['interestImg1'] != 0) $interests += 33.33;
      if($mProfile['interestImg2']!=null && $mProfile['interestImg2'] != 0) $interests += 33.33;
      if($mProfile['interestImg3']!=null && $mProfile['interestImg3'] != 0) $interests += 33.33;
      if($interests>99) $interests = 100;
      
    }
    $global = ($about + $greetings + $personality + $interests)/4;
    
    $data['about'] = round($about);
    $data['greetings'] = round($greetings);
    $data['personality'] = round($personality);
    $data['interests'] = round($interests);
    $data['global'] = round($global);
    return $data;
  }
  
  
  /*
   * Description: Calculate againt profile finished 
   */
  public function updateProcess($result) {
    $mProfile = new mProfile();
    $mProfile = $mProfile->getProfileByUserId(user()->getUserProperty('user_id'));
    $about = 0;
    $greetings = 0;
    $personality = 0;
    $interests = 0;
    $global = 0;
    if($mProfile!=false){
      if($mProfile['looking']!=null) $about += 6.25;
      if($mProfile['occupation']!=null) $about += 6.25;
      if($mProfile['education']!=null) $about += 6.25;
      if($mProfile['income']!=null) $about += 6.25;
      if($mProfile['religion']!=null) $about += 6.25;
      if($mProfile['political_affiliation']!=null) $about += 6.25;
      if($mProfile['where_i_grew_up']!='') $about += 6.25;
      if($mProfile['tall']!=null) $about += 6.25;
      if($mProfile['body_type']!=null) $about += 6.25;
      if($mProfile['hair_color']!=null) $about += 6.25;
      if($mProfile['eyes_color']!=null) $about += 6.25;
      if($mProfile['ethnicity']!=null) $about += 6.25;
      if($mProfile['marial_status']!=null) $about += 6.25;
      if($mProfile['children']!=null) $about += 6.25;
      if($mProfile['pet']!='') $about += 6.25;
      if($mProfile['smoke']!=null) $about += 6.25;
      if($mProfile['greeting1']!=null) $greetings += 33.33;
      if($mProfile['greeting2']!=null) $greetings += 33.33;
      if($mProfile['greeting3']!=null) $greetings += 33.33;
      if($greetings>99) $greetings = 100;
      
      $mAllQuestion = mPersonalityQuestions::model()->findAll('sex=:sex and active=1', array(':sex'=>$mProfile['gender']));
      $mQuesUserAns = mPersonalityQuestions::model()->getQuesUserAns($mProfile['gender'],$mProfile['user_id']);      
      if(count($mAllQuestion) == count($mQuesUserAns)){
        $personality = 100;
      }else{
        $percentOneQuestion = 100/count($mAllQuestion);
        $personality = round($percentOneQuestion * count($mQuesUserAns));
      }
      
      if($mProfile['interestImg1']!=null && $mProfile['interestImg1'] != 0) $interests += 33.33;
      if($mProfile['interestImg2']!=null && $mProfile['interestImg2'] != 0) $interests += 33.33;
      if($mProfile['interestImg3']!=null && $mProfile['interestImg3'] != 0) $interests += 33.33;
      if($interests>99) $interests = 100;
      
    }
    $global = ($about + $greetings + $personality + $interests)/4;
    $result['data']['completionData'][] = array('key' => 'global', 'value' => round($global));
    $result['data']['completionData'][] = array('key' => 'about', 'value' => round($about));
    $result['data']['completionData'][] = array('key' => 'greetings', 'value' => round($greetings));
    $result['data']['completionData'][] = array('key' => 'personality', 'value' => round($personality));
    $result['data']['completionData'][] = array('key' => 'interests', 'value' => round($interests));
    $result['data']['completionData'][] = array('key' => 'miniessays', 'value' => 0);
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  /*
   * Description: Calculate againt profile finished 
   */

  public function actionReloadProfileCompletion() {
    $result['Status'] = 'Success';
    $result['Message'] = null;
    $result['RequiresRefresh'] = false;
    $result['OveralCompleteness'] = 59;
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  public function actionProcessPageHome() {
    
    if (r()->isPostRequest) {
      $result = array();
      $result['Status'] = 'Success';
      $result['Message'] = null;
      $result['RequiresRefresh'] = false;
      $result['OveralCompleteness'] = 59;
      
      $mProfile = new mProfile();
      $key = $_POST['QuestionKey'];
      $ResponseKeys = isset($_POST['ResponseKeys']) ? $_POST['ResponseKeys'] : '';
      $ResponseValues = isset($_POST['ResponseValues']) ? $_POST['ResponseValues'] : '';
      if ($ResponseKeys == '' || $ResponseValues == '') {
        
      }

      $mUserAnswerQuestion = new mUserAnswerQuestion();
      $mUserAnswerQuestion = $mUserAnswerQuestion->find('user_id=:user_id and question_id=:question_id', array(':user_id' => user()->getUserProperty('user_id'), ':question_id' => $key));
      if (count($mUserAnswerQuestion) > 0) {
        $mUserAnswerQuestion->text = $ResponseValues;
      } else {
        $mUserAnswerQuestion = new mUserAnswerQuestion();
        $mUserAnswerQuestion->user_id = user()->getUserProperty('user_id');
        $mUserAnswerQuestion->question_id = $key;
        $mUserAnswerQuestion->text = $ResponseValues;
      }
      $mUserAnswerQuestion->save();
      //$result['data'] = array();
      //$result['data']['key'] = $key;

      $mGroupAnswerPerQues = new mGroupAnswerPerQues();
      $dataUserAnswer = $mGroupAnswerPerQues->getUserAnswer(user()->getUserProperty('user_id'));
      if($dataUserAnswer != false){
        $data = array('SiteId'=>21,'MemberId'=>user()->getUserProperty('user_id'),'ResponseText'=>'',
                      'IsDefaultResponseText'=>false,'MinLength'=>100,'MaxLength'=>500,'IsPending'=>false,
                      'SiteQuestionId'=>1,'iteQuestionResponseId'=>null);
        $data['SiteQuestionText'] = $dataUserAnswer['text'];
        $data['Key'] = $dataUserAnswer['id'];
        $result['data'] = $data;
      }
      
      echo CJSON::encode($result);
      Yii::app()->end();
      //$this->updateProcess($result);
    }
  }

  /**
   *  Description: Process update profile of user 
   * 
   */
  public function actionProcess() {

    if (r()->isPostRequest) {
      
    } else {
      
      $result = array();
      $result['Status'] = 'Success';
      $result['Message'] = null;
      $result['RequiresRefresh'] = false;

      $mProfile = new mProfile();
      $idArray = explode('&', $_SERVER["QUERY_STRING"]);
      foreach ($idArray as $index => $avPair) {
        list($ignore, $value) = explode("=", $avPair);
        $id[$ignore][] = $value;
      }
      $key = $_GET['QuestionKey'];
      $ResponseKeys = isset($id['ResponseKeys']) ? $id['ResponseKeys'] : '';
      $ResponseValues = isset($id['ResponseValues']) ? $id['ResponseValues'] : '';
      if ($ResponseKeys == '' || $ResponseValues == '') {
        $result['data'] = array();
        $result['data']['key'] = $key;
        $this->updateProcess($result);
      }

      if (isset($_GET['isQuestion']) && ($_GET['isQuestion'] == 'true' || $_GET['isQuestion'] == 1)) {
        
        $mUserAnswerQuestion = new mUserAnswerQuestion();
        $mUserAnswerQuestion = $mUserAnswerQuestion->find('user_id=:user_id and question_id=:question_id', array(':user_id' => user()->getUserProperty('user_id'), ':question_id' => $key));
        if (count($mUserAnswerQuestion) > 0) {
          $mUserAnswerQuestion->text = urldecode(implode(',', $ResponseValues));
        } else {
          $mUserAnswerQuestion = new mUserAnswerQuestion();
          $mUserAnswerQuestion->user_id = user()->getUserProperty('user_id');
          $mUserAnswerQuestion->question_id = $key;
          $mUserAnswerQuestion->text = urldecode(implode(',', $ResponseValues));
        }
        $mUserAnswerQuestion->save();
        $result['data'] = array();
        $result['data']['key'] = $key;

        $mGroupAnswerPerQues = new mGroupAnswerPerQues();
        $data = $mGroupAnswerPerQues->getTextByAttribute(implode(',', $ResponseValues), $key);

        if ($data == false) {
          $result['data']['formattedResponse'] = urldecode(implode(',', $ResponseValues));
        } else {
          $result['data']['formattedResponse'] = $data['text'];
        }

        $this->updateProcess($result);
      } else {
        
        if ($key == 'Age') {
          $this->datebirth($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Gender') {
          $this->Gender($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Height') {
          $this->Height($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Relationship_Expectations') {
          $this->looking($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Occupation') {
          $this->Occupation($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Education') {
          $this->Education($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Income') {
          $this->Income($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Religion') {
          $this->Religion($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Political_Affiliation') {
          $this->Political_Affiliation($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'General_Build') {
          $this->General_Build($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Hair_Color') {
          $this->Hair_Color($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Eye_Color') {
          $this->Eye_Color($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Ethnicity') {
          $this->Ethnicity($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Marital_Status') {
          $this->Marital_Status($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Number_of_Children') {
          $this->Number_of_Children($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Pet') {
          $this->Pet($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Smoking_Preference') {
          $this->Smoking_Preference($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'Smoking_Preference') {
          $this->Smoking_Preference($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'greeting-0') {
          $this->greeting_0($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'greeting-1') {
          $this->greeting_1($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'greeting-2') {
          $this->greeting_2($key, $ResponseKeys, $ResponseValues, $result);
        } else if ($key == 'MessageIdeas') {
          $this->MessageIdeas($key, $ResponseKeys, $ResponseValues, $result);
        }
      }
    }
    echo CJSON::encode($result);
    Yii::app()->end();
  }

  private function MessageIdeas($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'MessageIdeas';
    $result['Status'] = 'Success';

    $mProfile->updateProfile('message_ideas', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    //$data = Constant::getMessageIdeasArray();
    //$result['data']['formattedResponse'] = 'Your Message Ideas have been saved.';
    $this->updateProcess($result);
  }

  private function How_much_do_you_like_reading($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'How_much_do_you_like_reading';

    $mProfile->updateProfile('question7', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getLikeReadingArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function How_much_do_you_enjoy_going_to_live_theatre($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'How_much_do_you_enjoy_going_to_live_theatre';

    $mProfile->updateProfile('question6', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getLiveTheatreArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function Do_you_enjoy_going_to_the_movies($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Do_you_enjoy_going_to_the_movies';

    $mProfile->updateProfile('question5', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getGoMovieArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function How_punctual_are_you_typically($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'How_punctual_are_you_typically';

    $mProfile->updateProfile('question4', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getPunctualArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function Are_you_romantic($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Are_you_romantic';

    $mProfile->updateProfile('question3', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getRomanticArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function How_patient_do_you_consider_yourself($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'How_patient_do_you_consider_yourself';

    $mProfile->updateProfile('question2', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getConsiderArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function Do_you_enjoy_cooking($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Do_you_enjoy_cooking';

    $mProfile->updateProfile('question1', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getCookingrray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function greeting_0($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'greeting-0';

    $mProfile->updateProfile('greeting1', urldecode($ResponseValues[0]), Yii::app()->session['profileUser']['profile_id']);

    $result['data']['formattedResponse'] = urldecode($ResponseValues[0]);
    $this->updateProcess($result);
  }

  private function greeting_1($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'greeting-1';

    $mProfile->updateProfile('greeting2', urldecode($ResponseValues[0]), Yii::app()->session['profileUser']['profile_id']);

    $result['data']['formattedResponse'] = urldecode($ResponseValues[0]);
    $this->updateProcess($result);
  }

  private function greeting_2($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'greeting-2';

    $mProfile->updateProfile('greeting3', urldecode($ResponseValues[0]), Yii::app()->session['profileUser']['profile_id']);

    $result['data']['formattedResponse'] = urldecode($ResponseValues[0]);
    $this->updateProcess($result);
  }

  private function Smoking_Preference($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Smoking_Preference';

    $mProfile->updateProfile('smoke', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getSmokerArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function Pet($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Pet';

    $mProfile->updateProfile('pet', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getPetArray();
    $formattedResponse = '';
    $count = 0;
    foreach ($ResponseValues as $item) {
      if ($count == 0)
        $formattedResponse .= $data[$item];
      else
        $formattedResponse .= ', ' . $data[$item];
      $count++;
    }
    $result['data']['formattedResponse'] = $formattedResponse;
    $this->updateProcess($result);
  }

  private function Number_of_Children($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Number_of_Children';

    $mProfile->updateProfile('children', $ResponseValues[0], Yii::app()->session['profileUser']['profile_id']);
    $mProfile->updateProfile('children_living', $ResponseValues[1], Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getChildArray();
    $data1 = '';
    if ($ResponseValues[0] < 1) {
      $data1 = 'Has no children';
    } else {
      if (isset($ResponseValues[1]) && $ResponseValues[1] < 1) {
        $data1 = 'Has ' . $data[$ResponseValues[0]] . ' children';
      } else {
        $data1 = 'Has ' . $data[$ResponseValues[0]] . ' child, lives with ' . $data[$ResponseValues[1]];
      }
    }

    if ($data1 != '')
      $result['data']['formattedResponse'] = $data1;
    $this->updateProcess($result);
  }

  private function Marital_Status($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Marital_Status';

    $mProfile->updateProfile('marial_status', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getMaritalArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function Ethnicity($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Ethnicity';

    $mProfile->updateProfile('ethnicity', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getEthnicityArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function Eye_Color($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Eye_Color';

    $mProfile->updateProfile('eyes_color', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getColorArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function Hair_Color($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Hair_Color';

    $mProfile->updateProfile('hair_color', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getHairColorArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function General_Build($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'General_Build';

    $mProfile->updateProfile('body_type', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getBodyArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function Political_Affiliation($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Political_Affiliation';

    $mProfile->updateProfile('political_affiliation', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getPoliticalArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function Religion($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Religion';

    $mProfile->updateProfile('religion', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getReligionArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function Income($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Income';

    $mProfile->updateProfile('income', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getIncomeArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function Education($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Education';

    $mProfile->updateProfile('education', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);

    $data = Constant::getEducationArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function Occupation($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Occupation';

    $mProfile->updateProfile('occupation', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);
    //$data = array(-1=>'Choose',79=>'no answer',80=>'Administrative / Clerical',81=>'Architecture / Interior design',82=>'Artistic / Creative / Performance',83=>'Entertainment / Media',84=>'Executive / Management'
    //    ,85=>'Fashion / Beauty',86=>'Financial / Accounting / Real Estate',87=>'Labor / Construction',88=>'Law / Legal Services',89=>'Law Enforcement / Security / Military',90=>'Health / Medical / Dental / Veterinary',91=>'Nonprofit / Volunteer / Activist',92=>'Political / Government / Civil Service',93=>'Retail / Food Services'
    //    ,94=>'Sales / Marketing',95=>'Self-Employed / Entrepreneur',96=>'Student',97=>'Teacher / Professor / Education',98=>'Technical / Science / Computers / Engineering',99=>'Travel / Hospitality / Transportation',100=>'Other Profession');
    $data = Constant::getOccupationArray();
    $result['data']['formattedResponse'] = $data[$ResponseValues[0]];
    $this->updateProcess($result);
  }

  private function looking($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Relationship_Expectations';

    $mProfile->updateProfile('looking', implode(',', $ResponseValues), Yii::app()->session['profileUser']['profile_id']);
    $data = array(-1 => 'Marriage, Serious Relationship, Travel Partner, Casual Relationship, Friendship, Pen pal', 2 => 'Marriage', 4 => 'Serious Relationship', 8 => 'Travel Partner', 16 => 'Casual Relationship', 32 => 'Friendship', 64 => 'Pen pal');
    $formattedResponse = '';
    $count = 0;
    foreach ($ResponseValues as $item) {
      if ($count == 0)
        $formattedResponse .= $data[$item];
      else
        $formattedResponse .= ', ' . $data[$item];
      $count++;
    }
    $result['data']['formattedResponse'] = $formattedResponse;
    $this->updateProcess($result);
  }

  private function Height($key, $ResponseKeys, $ResponseValues, $result) {
    $height1 = array('4.5' => '4\' 5"', '4.6' => '4\' 6"', '4.7' => '4\' 7"', '4.8' => '4\' 8"', '4.9' => '4\' 9"', '4.10' => '4\' 10"', '4.11' => '4\' 11"',
        '5.0' => '5\' 0"', '5.1' => '5\' 1"', '5.2' => '5\' 2"', '5.3' => '5\' 3"', '5.4' => '5\' 4"', '5.5' => '5\' 5"', '5.6' => '5\' 6"', '5.7' => '5\' 7"', '5.8' => '5\' 8"', '5.9' => '5\' 9"', '5.10' => '5\' 10"', '5.11' => '5\' 11"',
        '6.0' => '6\' 0"', '6.1' => '6\' 1"', '6.2' => '6\' 2"', '6.3' => '6\' 3"', '6.4' => '6\' 4"', '6.5' => '6\' 5"', '6.6' => '6\' 6"', '6.7' => '6\' 7"', '6.8' => '6\' 8"', '6.9' => '6\' 9"', '6.10' => '6\' 10"', '6.11' => '6\' 11"',
        '7.0' => '7\' 0"', '7.1' => '7\' 1"', '7.2' => '7\' 2"', '7.3' => '7\' 3"', '7.4' => '7\' 4"', '7.5' => '7\' 5"', '7.6' => '7\' 6"', '7.7' => '7\' 7"', '7.8' => '7\' 8"', '7.9' => '7\' 9"', '7.10' => '7\' 10"', '7.11' => '7\' 11"'
    );
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Height';
    $mProfile->updateProfile('tall', $ResponseValues[0] * 30.48, Yii::app()->session['profileUser']['profile_id']);
    $result['data']['formattedResponse'] = $height1["$ResponseValues[0]"];
    $this->updateProcess($result);
  }

  private function Gender($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Gender';
    $mProfile->updateProfile('gender', $ResponseValues[0], Yii::app()->session['profileUser']['profile_id']);
    if ($ResponseValues[0] == 'Male' && $ResponseValues[1] == 'Male') {
      $mProfile->updateProfile('seeking', 2, Yii::app()->session['profileUser']['profile_id']);
      $mProfile->updateUser('seeking', 2, Yii::app()->session['profileUser']['user_id']);
    } else if ($ResponseValues[0] == 'Male' && $ResponseValues[1] == 'Female') {
      $mProfile->updateProfile('seeking', 1, Yii::app()->session['profileUser']['profile_id']);
      $mProfile->updateUser('seeking', 1, Yii::app()->session['profileUser']['user_id']);
    } else if ($ResponseValues[0] == 'Female' && $ResponseValues[1] == 'Male') {
      $mProfile->updateProfile('seeking', 3, Yii::app()->session['profileUser']['profile_id']);
      $mProfile->updateUser('seeking', 3, Yii::app()->session['profileUser']['user_id']);
    } else if ($ResponseValues[0] == 'Female' && $ResponseValues[1] == 'Female') {
      $mProfile->updateProfile('seeking', 4, Yii::app()->session['profileUser']['profile_id']);
      $mProfile->updateUser('seeking', 4, Yii::app()->session['profileUser']['user_id']);
    }
    $result['data']['formattedResponse'] = $ResponseValues[0] . ' seeking ' . $ResponseValues[1];
    $this->updateProcess($result);
  }

  private function datebirth($key, $ResponseKeys, $ResponseValues, $result) {
    $mProfile = new mProfile();
    $result['data'] = array();
    $result['data']['key'] = 'Age';
    $birthdate = $ResponseValues[2] . '-' . $ResponseValues[0] . '-' . $ResponseValues[1];
    if ($this->validateBirthdate($birthdate) == 1) {
      $result['Status'] = 'Success';
      $result['Message'] = null;
      $result['RequiresRefresh'] = false;
      $mProfile->updateProfile('birthdate', $birthdate, Yii::app()->session['profileUser']['profile_id']);
      $result['data']['formattedResponse'] = $this->calculateYearOld($birthdate);
    } else {
      $result['Status'] = 'Failure';
      $result['Message'] = 'You must be at least 18 years of age to use this site.';
      $result['RequiresRefresh'] = false;
    }
    $this->updateProcess($result);
  }

  private function validateBirthdate($birthdate) {
    $date1 = new DateTime($birthdate);
    $date2 = new DateTime(date("Y-m-d"));

    $interval = $date1->diff($date2);
    if ($interval->y < 18)
      return 0;
    else
      return 1;
  }

  private function calculateYearOld($birthdate) {
    $date1 = new DateTime($birthdate);
    $date2 = new DateTime(date("Y-m-d"));

    $interval = $date1->diff($date2);
    return $interval->y;
  }

}